class H5timeNotice < ActiveRecord::Base
  serialize :startTime
  serialize :itinerary

  def self.getH5timeNotice(object_id)
    _notices = self.where(:object_id => object_id)
    _h5_notice = []
    _notices.each do |tn|
      data_title = {}
      data = {
        :title => tn.title.to_s,
        :startTime => tn.startTime,
        :itinerary => tn.itinerary
      }
      data_title[tn.time] = data
      _h5_notice << data_title
    end
    _h5_notice
  end

  def self.postH5timeNotice(object_id,from_object_id,data_key,data_value)
    data = data_value.to_h
    data["time"] = data_key
    data["object_id"] = object_id
    data["from_object_id"] = from_object_id
    Rails.logger.info("===notice data =====#{data_key}=====>#{data}")
    arr_data = []
    data.each do |dtk,dtv|
      if(dtv.class.to_s == "Hashie::Mash")
        data[dtk] = dtv.to_h
      end
    end
    arr_data << data
    self.create(arr_data)
  end
  def self.putH5timenotice

  end
  def self.deleteh5timeNotice(object_id, time)
    _notice =   self.find_by(:object_id => object_id, :time => time)
    unless _notice.blank?
      _notice.destroy
    end
  end
end
